import Vue from 'vue';
import axios from 'axios';
import { Toast } from 'vant';

Vue.use(Toast);

const axios_maizuo = axios.create({
  baseURL: 'https://m.maizuo.com',
  timeout: 30000,
  headers: {
    'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.0.4","e":"16198591965838634376757249","bc":"310100"}',
    'X-Host': 'mall.film-ticket.film.info',
  },
});

// Add a request interceptor
axios_maizuo.interceptors.request.use(
  function(config) {
    Toast.loading({
      message: 'Loading...',
      forbidClick: true,
      loadingType: 'spinner',
      duration: 0,
    });
    return config;
  },
  function(error) {
    return Promise.reject(error);
  }
);

// Add a response interceptor
axios_maizuo.interceptors.response.use(
  function(response) {
    Toast.clear();
    return response;
  },
  function(error) {
    return Promise.reject(error);
  }
);

export default axios_maizuo;
